import {useIntersectionObserver} from "@vueuse/core";

export const lazyPlugin={
    install (app:any){
        app.directive('img-lazy',{
            mounted(el:any,binding:any){
                const {stop} = useIntersectionObserver(
                    el,([{isIntersecting}])=>{
                        //进入视口区域
                        if(isIntersecting){
                            el.src=binding.value;
                            stop();//避免重复监听
                        }
                    },
                )
            }
        })
    }
}